PROJECT #2 | LIVE SESSIONS WK3 & WK4

Foreign Exchange Market Interactions

OVERVIEW:

Part 1:

Initial Exploratory Data Analysis

QUESTIONS
  1. What is the nature of exchange rates in general and in particular for this data set?
  2. What do the mean, standart deviation etc. tell us about the data set?

Part 2:

Business Analysis

QUESTIONS
  1. How can we show the shape of our exposure to euros, especially given our tolerance for risk?
  2. What is the history of correlations in the exchange rate markets?
  3. There doesn’t appear to be a question 3
  4. How are correlations adn volatilities? Do we have to be concerned that inter-market transactions can impact transactions in a single market?

====================================

PART 1:

Problem:

International exchange rates continue to (negatively) impact our bottom line.

Business Question:

  1. What is the nature of exchange rates in general and in particular for this data set?

BIG PICTURE: WHAT WE’RE DOING:

We want to reflect the upds and downs of rate movements (a.k.a. currency appreciation and depreciation) to better understand exchange rate volitility.

BIG PICTURE: HOW WE’RE DOING IT:

  1. We’ll calculate percentage changes as log returns of currency pairs in the data set exrates.csv, provided by our business partners
  2. We want to zero in on the ups and downs, so we will use if and else statements to define a new column direction and house this new information in a data frame
  3. Using this new data frame, we will interpret appreciation and depreciation in terms of the impact on the receipt of cash flow from customer’s accounts that are different from our USD functional currency.( TL;DR: We will look at the ups and downs of everything other than the USD)

Data Prep and Preliminary Analysis

WHAT WE’RE DOING:

Importing & examining our data

HOW WE’RE DOING IT:

  1. Load in the libraries we know we’ll need
  1. Read in the data
  2. Remove the missing data
  3. View our newly imported data
  1. head() shows our first few entries
  2. tail() shows our last few entries
  3. str() shows the structure of the data
  4. summary() shows a crisp, clean summary of descriptive stats
library(zoo)
library(xts)
library(ggplot2)
exrates <- na.omit(read.csv("data/exrates.csv", header = TRUE))
# head(exrates)
plot(head(exrates))

plot(tail(exrates))

plot(head(exrates), tail(exrates))

# tail(exrates)
# print('======= STRUCTURE =======')
# str(exrates)
# print('======= SUMMARY =======')
# summary(exrates)

EDA PT1: Construct & Calculate

WHAT WE’RE DOING:

Constructing a new data frame with additional calculations to help better address our business question

HOW WE’RE DOING IT:

  1. Computing log differences percent (using as.matrix to force numeric type)
  2. Creating a size column by taking the absolute value of what we created in (1) above because size is an indicator of volitity
  3. Creating a direction column by using ifelse statements to determine the “direction” of the market
  4. Converting the dates into a time series object

– a. Split into date and rates – b. Make an xts object with row and names equal to the dates 5. Creating our new data frame 6. Viewing our data frame using ggplot2 and plotly

exrates.r <- diff(log(as.matrix(exrates[, -1]))) * 100
# head(exrates.r)
# tail(exrates.r)
# str(exrates.r)
size <- na.omit(abs(exrates.r))
# head(size)
direction <- ifelse(exrates.r > 0, 1, ifelse(exrates.r < 0, -1, 0))
dates <- as.Date(exrates$DATE[-1], "%m/%d/%Y")
values <- cbind(exrates.r, size, direction)
exrates.df <- data.frame(dates = dates, returns = exrates.r, size = size, direction = direction)
exrates.xts <- na.omit(as.xts(values, dates))
exrates.zr <- na.omit(as.zooreg(exrates.xts))
library(ggplot2)
library(plotly)
title.chg <- "Exchange Rate Percent Changes"
p1 <- autoplot.zoo(exrates.xts[,1:4]) + ggtitle(title.chg) + ylim(-5, 5)
p2 <- autoplot.zoo(exrates.xts[,5:8]) + ggtitle(title.chg) + ylim(-5, 5)
ggplotly(p1)

EDA PT2: MORE VISUALIZATIONS

acf(coredata(exrates.xts[ , 1:4])) 

acf(coredata(exrates.xts[ , 5:8])) 

pacf(coredata(exrates.xts[ , 1:4])) 

pacf(coredata(exrates.xts[ , 5:8])) 

data_moments <- function(data){
  library(moments)
  library(matrixStats)
  mean.r <- colMeans(data)
  median.r <- colMedians(data)
  sd.r <- colSds(data)
  IQR.r <- colIQRs(data)
  skewness.r <- skewness(data)
  kurtosis.r <- kurtosis(data)
  result <- data.frame(mean = mean.r, median = median.r, std_dev = sd.r, IQR = IQR.r, skewness = skewness.r, kurtosis = kurtosis.r)
  return(result)
}
answer <- data_moments(exrates.xts[,5:8])
answer <- round(answer, 4)
knitr::kable(answer)
mean median std_dev IQR skewness kurtosis
USD.EUR 0.7185 0.5895 0.5499 0.7506 1.3773 6.3808
USD.GBP 0.6884 0.5601 0.6565 0.6588 4.0555 34.3779
USD.CNY 0.1700 0.1118 0.2233 0.1536 4.9157 41.4959
USD.JPY 0.8310 0.6358 0.7371 0.8352 1.6373 6.3185

PART 2

FIN.